package com.android.equipment.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.LinearLayout
import com.android.equipment.R
import com.android.equipment.bean.WorkDetailPeopleData
import com.blankj.utilcode.util.StringUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class SelectPeopleAdapter(layoutRes: Int) :
    BaseQuickAdapter<WorkDetailPeopleData, BaseViewHolder>(layoutRes) {
    override fun convert(holder: BaseViewHolder, people: WorkDetailPeopleData) {
        val peoplePhoto: String = people.peoplePhoto
        val ivPhoto = holder.getView<ImageView>(R.id.iv_photo)
        if (!StringUtils.isEmpty(peoplePhoto)) {
            Glide.with(context)
                .load("file://$peoplePhoto") // 使用 file:// URI 加载本地图片
                .into(ivPhoto)
        }
        holder.setText(R.id.tv_people_name, people.peopleName)
        holder.setText(R.id.tv_people_phone, people.peoplePhone)
        if (people.isExit) {
            holder.itemView.isEnabled = false
            holder.getView<LinearLayout>(R.id.ll_item)
                .setBackgroundResource(R.drawable.shape_radius_5_solid_f2f2f2)
            holder.setTextColor(R.id.tv_people_name, Color.parseColor("#999999"))
            holder.setTextColor(R.id.tv_people_phone, Color.parseColor("#999999"))
        } else {
            holder.itemView.isEnabled = true
            holder.getView<LinearLayout>(R.id.ll_item)
                .setBackgroundResource(R.drawable.shape_radius_5_solid_white_stroke_1_f2f2f2)
            holder.setTextColor(R.id.tv_people_name, Color.parseColor("#333333"))
            holder.setTextColor(R.id.tv_people_phone, Color.parseColor("#333333"))
        }
    }
}